﻿using System.Collections.ObjectModel;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using SimpleToDoList.Models;

namespace SimpleToDoList.ViewModels;

public partial class MainWindowViewModel : ViewModelBase {
    public ObservableCollection<ToDoItemViewModel> ToDoItems { get; } = new ObservableCollection<ToDoItemViewModel>();

    [ObservableProperty] [NotifyCanExecuteChangedFor(nameof(AddItemCommand))]
    private string? _newItemContent;

    private bool CanAddItem() => !string.IsNullOrWhiteSpace(NewItemContent);

    [RelayCommand(CanExecute = nameof(CanAddItem))]
    private void AddItem() {
        ToDoItems.Add(new ToDoItemViewModel(new ToDoItem { Content = NewItemContent, IsChecked = false}));
        NewItemContent = string.Empty;
    }

    [RelayCommand]
    private void RemoveItem(ToDoItemViewModel item) {
        ToDoItems.Remove(item);
    }
}